package club.codeworker.commonscodecdemo.config;

import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;

/**
 * Description: 自定义的加密配置类
 *
 * @author code-worker
 * @date 2021/09/05 22:32
 */
@Component
public class MyPasswordEncoder {
    /**
     * task: 数据加密
     * @date 2021/9/5 22:44
     * @param rawPassword 待加密数据
     * @return java.lang.String
     */
    public String encode(CharSequence rawPassword) {
        return DigestUtils.md5DigestAsHex(rawPassword.toString().getBytes());
    }

    /**
     * task: 数据比对校验
     * @date 2021/9/5 22:45
     * @param rawPassword 未加密数据
     * @param encodedPassword 加密数据
     * @return boolean
     */
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        return encodedPassword.equals(encode(rawPassword));
    }
}
